from PySide6 import QtWidgets
from PySide6.QtWidgets import QWidget
from PySide6.QtCharts import QChart, QChartView, QBarSet, QBarSeries, QBarCategoryAxis
from PySide6.QtCore import Qt

class Demo(QWidget):
    """Bar Chart Demo Class."""
    def __init__(self, parent=None):
        super().__init__(parent)
        
        # Create chart
        self.chart = QChart()
        self.chart.setTitle("Bar Chart Example")
        
        # Create bar series
        set0 = QBarSet("Product A")
        set1 = QBarSet("Product B")
        set2 = QBarSet("Product C")
        
        # Add data
        set0 << 1 << 2 << 3 << 4 << 5 << 6
        set1 << 5 << 0 << 0 << 4 << 0 << 7
        set2 << 3 << 5 << 8 << 13 << 8 << 5
        
        series = QBarSeries()
        series.append(set0)
        series.append(set1)
        series.append(set2)
        
        self.chart.addSeries(series)
        
        # Create categories
        categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
        axisX = QBarCategoryAxis()
        axisX.append(categories)
        self.chart.addAxis(axisX, Qt.AlignBottom)
        series.attachAxis(axisX)
        
        axisY = QBarCategoryAxis()
        axisY.setRange("0", "15")
        self.chart.addAxis(axisY, Qt.AlignLeft)
        series.attachAxis(axisY)
        
        # Create chart view
        chart_view = QChartView(self.chart)
        self.layout = QtWidgets.QVBoxLayout()
        self.layout.addWidget(chart_view)
        self.setLayout(self.layout)

def runDemo(parent):
    widget = Demo(parent)
    return widget